<?php
namespace App\Api\Controllers;

use App\Http\Controllers\Controller;
use App\Api\Services\JsonService;
use Illuminate\Http\Request;
use App\Api\Models\Goods;

class SalesVolumeController extends Controller
{
    public function getSalesRanking()
    {
        $goodsData = Goods::getRankList();

        $arr = [];
        $all =[];

        foreach($goodsData as $k=>$v){
            $arr[] = $goodsData[$k];
        }

        foreach($arr as $key=>$val){
            $all[] = $val;
        }

        foreach ($all as $k=>$v){
            $ids[$k] = $v['goods_name'];
        }

        $first = array_count_values ($ids);

        if($first){
            return JsonService::success($first);
        }
        return JsonService::fail('排行榜数据为空');
    }

    public function getYesterdaySale()
    {
        $goodsData = Goods::getYestSaleList();

        $all =[];

        foreach($goodsData as $k=>$v){
            foreach($goodsData[$k] as $key=>$val){
                $all[] = $val;
            }
        }

        if($all){
            return JsonService::success($all);
        }
        return JsonService::fail('昨日排行榜数据为空');
    }
}